import { IFetchListProps } from "@/hooks/type";
import { IActivityParams } from "@/pages/activityManage/activityManage.type";
import { useEffect, useState } from "react";
/**
 *获取列表数据的hook
 */
export default function useFetchList<Response>(
  props: IFetchListProps<Response>
) {
  const [dataSource, setDataSource] = useState<Response[]>([]);
  const [total, setTotal] = useState(0);
  const [filterParams, setFilterParams] = useState(new IActivityParams());
  useEffect(() => {
    getData();
  }, [filterParams]);

  //获取数据
  const getData = async () => {
    const res = await props.API(filterParams);
    setDataSource(res.data);
    setTotal(res.total);
  };
  return { dataSource, total, filterParams, setFilterParams };
}
